package com.taxigang.server;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.google.appengine.api.datastore.Key;
import com.taxigang.shared.RouteInfo;
import com.taxigang.shared.TaxiCompanyInfo;

/**
 *
 * @author hall
 */
@Entity
@Table(name = "ROUTE")
public class Route implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ROUTEKEY", nullable = false)
	private Key key;
	@Column(name = NAME, nullable = true)
	private String name;
	@Column(name = START_CITY, nullable = true)
	private String startCity;
	@Column(name = START_ADDRESS, nullable = true)
	private String startAddress;
	@Column(name = DEST_CITY, nullable = true)
	private String destinationCity;
	@Column(name = DEST_ADDRESS, nullable = true)
	private String destinationAddress;



	public static final  String NAME="NAME";
	public static final  String START_CITY="START_CITY";
	public static final  String START_ADDRESS="START_ADDRESS";
	public static final  String DEST_CITY="DEST_CITY";
	public static final  String DEST_ADDRESS="DEST_ADDRESS";


	public Route() {
	}

	public long getId() {
		return key.getId();
	}

	public RouteInfo getInfo(){
		RouteInfo info =  new RouteInfo();
		info.setId(""+getId());
		info.setName(name);
		info.setDestination(destinationAddress);
		info.setStart(startAddress);
		return info;
	}


	public void setInfo(RouteInfo info){
		name =info.getName();
		startCity ="";
		startAddress =info.getStart();
		destinationCity ="";
		destinationAddress =info.getDestination();
	}


	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof Route)) {
			return false;
		}
		Route other = (Route) object;
		if ((this.key == null && other.key != null) || (this.key != null && !this.key.equals(other.key))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "taxigangsystem.beans.Partner[partner=" + key.getId() + "]";
	}

}
